package com.syy.api.system.mapper;

import com.syy.api.system.dto.RolePageReqVO;
import com.syy.common.core.domain.BaseEntity;
import com.syy.common.core.domain.BaseMapperX;
import com.syy.common.core.domain.PageResult;
import com.syy.common.core.domain.entity.SysRole;
import com.syy.system.mapper.LambdaQueryWrapperX;
import org.springframework.lang.Nullable;

import java.util.Collection;
import java.util.List;

public interface RoleMapper extends BaseMapperX<SysRole> {

    default PageResult<SysRole> selectPage(RolePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysRole>()
                .likeIfPresent(SysRole::getRoleName, reqVO.getName())
                .eqIfPresent(SysRole::getStatus, reqVO.getStatus())
                .betweenIfPresent(BaseEntity::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(SysRole::getRoleSort));
    }

    default SysRole selectByName(String name) {
        return selectOne(SysRole::getRoleName, name);
    }

//    default SysRole selectByCode(String code) {
//        return selectOne(SysRole::getCode, code);
//    }

    default List<SysRole> selectListByStatus(@Nullable Collection<Integer> statuses) {
        return selectList(SysRole::getStatus, statuses);
    }
}
